<template>
  <div class="index-news-detail clearfix">
    <mainLes v-if="con.toLink" :con="con"/>
  </div>
</template>
<script>
import {ajax,showToast} from '@/utils/js.js'
import { getNewsDetail,gongaoDetails } from '@/services/api.js'
import mainLes from '@/components/detail.vue'
const log = console.log
export default {
  components:{
    mainLes
  },
  data() {
    return {
      type:0,
      con:{},
      id:'', //文章id
    }
  },
  mounted(){
    
    let data = this.$route.query
    log(data)
    this.content(data.id,data.type)
    this.type = data.type;
    this.id = data.id;
  },
  computed:{
    nav(){
      let data=[
        {name:this.$t('news.news'),id:0},
        {name:this.$t('news.event'),id:1}
      ]
      return data
    },
  },
  watch:{
    '$i18n.locale'(){
      this.content()
    },
  },
  methods:{
    tab(e){
      this.type = e.id
      
    },
    content(id = this.id,type = this.type){
      let url
      if(type == 0){
        url = getNewsDetail
      }else{
        url = gongaoDetails
      }
      log('url',url)
      ajax(this,url,{id},res=>{
        this.con = res.data;
        this.con.toLink = '/news?type='+this.type
        this.con.curListName = this.nav[this.type].name
      },err=>{
        showToast(this,err.msg)
      })
    },
    //首页跳转
    indexLink(data){
     if(data.outLink && data.outLink==1){
        window.open(data.linkUrl,'-blank')
      }else{
        window.location.href = data.linkUrl
      }
    },
    
  }
}
</script>
<style lang="scss">
  .index-news-detail{
    .content{
      padding:40px 120px;
      background-color: #fff;
      .time{
        padding: 20px 0;
      }
      .con{line-height: 1.8;color: #666;}
    }
    
    
  }
</style>